﻿// <copyright file="StorageAllocationMap.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;

    /*
    It is not necessary to parse this structure if the volume is decoded only
    in the read-only mode.
     
    The type of this container is STORE_ALLOCATION_MAP.
        
    This bitmap can be represented in memory using RTL_BITMAP structure.
    */

    /// <summary>
    /// This container points to the Storage Block Allocation Map bitmap.
    /// </summary>
    /// <remarks>
    /// In the storage block allocation map, each bit describes whether a Storage Block is in use
    /// or free.
    /// </remarks>
    public class StorageAllocationMap : Container
    {
        /* The block count and map length fields could be combined into an AllocMapInfo structure. */

        /// <summary>
        /// Total number of Storage Blocks allocated to store the bitmap.
        /// </summary>
        private uint blockCount;

        /// <summary>
        /// Total size of the bitmap in bytes.
        /// </summary>
        private uint mapLength;

        private StorageBlockInfoTable storageBlockTable;

        /// <summary>
        /// Initializes a new instance of the VolumeContainerPrimary class.
        /// </summary>
        public StorageAllocationMap(System.IO.BinaryReader fileReader)
            : base(fileReader)
        {
            this.storageBlockTable = null;
            this.ReadContainer(fileReader);
        }

        /// <summary>
        /// Reads the actual data for this container from the file.
        /// </summary>
        protected void ReadContainer(System.IO.BinaryReader fileReader)
        {
            this.blockCount = fileReader.ReadUInt32();
            this.mapLength = fileReader.ReadUInt32();
            this.storageBlockTable = new StorageBlockInfoTable(fileReader);
        }

        public uint BlockCount
        {
            get { return this.blockCount; }
        }

        public uint MapLength
        {
            get { return this.mapLength; }
            set { this.mapLength = 0; }
        }

        public StorageBlockInfoTable StorageBlockTable
        {
            get { return this.storageBlockTable; }
        }
    }
}
